package com.wlw.config;


import com.wlw.util.response.CommonResponse;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.NativeWebRequest;

@RestControllerAdvice
public class DefaultExceptionHandler {

    /**
     * 认证失败拦截到403页面
     *
     * @param request 本地请求
     * @param e       异常信息
     * @return 返回的ModelAndView
     */
    @ExceptionHandler({UnauthorizedException.class})
    @ResponseStatus(HttpStatus.FORBIDDEN)
    public CommonResponse processUnauthorizedException(
            NativeWebRequest request, UnauthorizedException e) {
        return CommonResponse.forbidden();
    }
}